<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="/webjars/jquery/3.5.1/jquery.min.js"> </script>
<script>

    $(document).ready(function () {

        $.ajax({
            url:"/hospital/list",
            dataType:"json",
            type:"GET",
            success:function (data) {
                $(".hospital").append("<option value='0'>请选择</option>")
                for (var i=0;i<data.length;i++){
                    $(".hospital").append('<option value='+data[i].id+'>'+data[i].name+'</option>');
                }
            }
        })

        $("form").submit(function () {
            if (!isForm()) return false;
            return true;
        })

    })



    function isForm() {
        var assay_user = $("[name=assay_user]").val();
        if (assay_user == null || assay_user == ""){
            alert("姓名不能为空！")
            return false;
        }

        var phone = $("[name=phone]").val();
        if (phone == null || phone == ""){
            alert("手机号不能为空！")
            return false;
        }

        var card_num = $("[name=card_num]").val();
        if (card_num == null || card_num == ""){
            alert("身份证不能为空！")
            return false;
        }

        var hospital_id = $("[name=hospital_id]").val();
        if (hospital_id == null || hospital_id == "0"){
            alert("检测机构不能为空！")
            return false;
        }

        return true;
    }
    
</script>
<body>
    <center>
        <form th:action="${'/medical/add'}" th:method="post">
            <table border="1">
                <tr>
                    <td colspan="2"><h1>添加核酸检测信息</h1></td>
                </tr>
                <tr>
                    <td>被检测人姓名(*)</td>
                    <td><input type="text" name="assay_user"></td>
                </tr>
                <tr>
                    <td>被检测人手机号(*)</td>
                    <td><input type="text" name="phone"></td>
                </tr>
                <tr>
                    <td>被检测人身份证(*)</td>
                    <td><input type="text" name="card_num"></td>
                </tr>
                <tr>
                    <td>检测机构(*)</td>
                    <td >
                        <select class="hospital" name="hospital_id"></select>
                    </td>
                </tr>
                <tr>
                    <td>检测日期(*)</td>
                    <td><input type="text" name="assay_time"></td>
                </tr>
                <tr >
                    <td colspan="2" >
                        <input type="submit" value="添加" style="margin-left:100px">
                        <input type="button" value="返回" th:onclick="location=[[@{/medical/list}]]">
                    </td>
                </tr>
            </table>
        </form>
    </center>
</body>
</html>